/**
 * 
 */
package com.training.hibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 189833
 * 
 */
public abstract class HibernateUtil {

    private static final Logger   log            = LoggerFactory.getLogger( HibernateUtil.class );

    private static SessionFactory sessionFactory = null;

    static {
        try {
            log.info( "Creating hibernate session factory" );
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
            log.info( "Successfully created hibernate session factory" );
        } catch ( Exception e ) {
            log.error( "Initial SessionFactory creation failed.",
                       e );
            throw new ExceptionInInitializerError( e );
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void shutdown() {
        getSessionFactory().close();
    }
}
